import { Controller, Get, Res } from '@nestjs/common';
import { join } from 'path';
import { readFile } from 'fs/promises';

@Controller('resource')
export class AppController {
  // 获取省市区数据
  @Get('region')
  async getRegionData(@Res() res) {
    try {
      const filePath = join(__dirname, '..', 'public', 'citypicker.json');
      const fileContent = await readFile(filePath, 'utf-8');
      const jsonData = JSON.parse(fileContent);

      return res.json(jsonData);
    } catch (error) {
      return res.status(500).json({ error: 'Internal Server Error' });
    }
  }
}
